
export default {
    canUndo: true,
    execute: (context, options, isUndo) => {
        const { sheet, selections } = options;

        sheet.suspendPaint();
        try {
            if (isUndo) {
                selections.forEach(detail => {
                    for (let row = detail.row, i = 0; i < detail.rowCount; i++ , row++) {
                        for (let col = detail.col, j = 0; j < detail.colCount; col++ , j++) {
                            sheet.getCell(row, col).value(options._oldCellText[row][col])
                        }
                    }
                });
            } else {
                options._oldCellText = {};
                selections.forEach(detail => {
                    for (let row = detail.row, i = 0; i < detail.rowCount; i++ , row++) {
                        if (!options._oldCellText[row]) {
                            options._oldCellText[row] = {};
                        }
                        for (let col = detail.col, j = 0; j < detail.colCount; j++ , col++) {
                            const cell = sheet.getCell(row, col);
                            options._oldCellText[row][col] = cell.value();
                            if (cell.cellType() && cell.cellType().viewAttr != 1) {
                                if ('WeaPicCellType' === cell.cellType().typeName) {
                                    const fileList = cell.value();
                                    fileList.map(o => {
                                        const { fileid } = o;
                                        const picName = `f,${row},${col},${fileid}`;
                                        sheet.floatingObjects.remove(picName)
                                    })
                                    cell.value([]);
                                }
                                cell.text(undefined)
                            }
                        }
                    }
                });
            }
        } catch (e) {
            if (!!(window.console && window.console.log)) {
                window.console.log(e);
            }
        }
        sheet.resumePaint();
    }

}